// require jquery
// http://stackoverflow.com/questions/1184624/convert-form-data-to-js-object-with-jquery

define(['jquery'], function ($) {

    if (!$.fn.serializeObject) {
        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    }


    var myUtils = {};

    // ?a=b&c=d => {a:b,c:d}
    myUtils.parseQueryString = function (qs) {
        var qs = qs.replace(/^\s?\?/, "");//去掉?
        var arr = qs.split('&');
        var obj = {};
        arr.forEach(function (item) {
            var key = item.split('=')[0];
            var val = item.split('=')[1];
            obj[key] = val;
        });

        return obj;
    };

    return myUtils;

});
